local sk__renzheng = fk.CreateSkill {

  name = "sk__renzheng",

  tags = {},

}



sk__renzheng:addEffect("active", {
  name = "sk__renzheng",
  anim_type = "support",
  prompt = function(self)
    return "#" .. self.interaction.data
  end,
  min_card_num = function(self)
    if self.interaction.data == "sk__renzheng_card" then
      return 1
    else
      return 0
    end
  end,
  max_card_num = function(self)
    if self.interaction.data == "sk__renzheng_card" then
      return 999
    else
      return 0
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(sk__renzheng.name, Player.HistoryPhase) == 0
  end,
  interaction = function()
    return UI.ComboBox { choices = { "sk__renzheng_card", "sk__renzheng_skill" } }
  end,
  card_filter = function(self, player, to_select, selected)
    if self.interaction.data == "sk__renzheng_card" then
      return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    else
      return false
    end
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if #selected == 0 and to_select ~= player then
      if self.interaction.data == "sk__renzheng_card" then
        return true
      else
        return true
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if self.interaction.data == "sk__renzheng_card" then
      room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, sk__renzheng.name, nil, false, player)
    else
      local skills = table.filter(player:getSkillNameList(), function(skill)
        return Fk.skills[skill]:isPlayerSkill(player) and Fk.skills[skill].visible and not target:hasSkill(skill, true)
      end)
      if #skills > 0 then
        local choices = room:askToChoices(player, {
          choices = skills,
          min_num = 1,
          max_num = #skills,
          skill_name = sk__renzheng.name,
          prompt = "#sk__renzheng-choose::" .. target.id,
          cancelable = false,
          detailed = true,
        })
        room:handleAddLoseSkills(target, choices, nil, true, false)
        room:handleAddLoseSkills(player, "-" .. table.concat(choices, "|-"), nil, true, false)
      end
    end
    if player.dead then return end
    local mark = player:getTableMark(sk__renzheng.name)
    if not table.contains(mark, target.id) then
      table.insert(mark, target.id)
      room:setPlayerMark(player, sk__renzheng.name, mark)
      if room:askForSkillInvoke(player, sk__renzheng.name, nil, "#sk__renzheng-invoke::" .. target.id) then
        room:changeMaxHp(player, 1)
        if not player.dead and player:isWounded() then
          room:recover({
            who = player,
            num = 1,
            recoverBy = player,
            skillName = sk__renzheng.name
          })
        end
        if target.dead then return end
        room:changeMaxHp(target, 1)
        if not target.dead and target:isWounded() then
          room:recover({
            who = target,
            num = 1,
            recoverBy = player,
            skillName = sk__renzheng.name
          })
        end
      end
    end
  end,
})

return sk__renzheng
